package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.ApArticleConfigMapper;
import com.zhentao.model.article.pojo.ApArticleConfig;
import com.zhentao.model.comment.dtos.CommentConfigDto;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.service.ApArticleConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;

    @Override
    public void UpdateByMap(Map map) {
        /**
         * 在自媒体端的  0-下架   1-上架
         * 在app端的    1-下架   0-上架
         */
        Object enable = map.get("enable");
        Integer isDown = null;
        if (enable.equals(1)) {
            isDown = 0;
        } else {
            isDown = 1;
        }

        // 修改articleconfig 里面的isDown
        apArticleConfigMapper.updateArticleConfigIsDown(map.get("articleId"), isDown);
    }

    /**
     * 修改文章评论状态
     *
     * @return
     */
    @Override
    public ResponseResult updateCommentStatus(CommentConfigDto dto) {
        update(Wrappers.<ApArticleConfig>lambdaUpdate()
                .eq(ApArticleConfig::getArticleId, dto.getArticleId())
                .set(ApArticleConfig::getIsComment, dto.getOperation()));
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
